<?php

/**
 * 图片字段表单组合处理
 * @param type $field 字段名
 * @param type $value 字段内容
 * @param type $fieldinfo 字段配置
 * @return type
 */
function image($field, $value, $fieldinfo) {
    //错误提示
    $errortips = $fieldinfo['errortips'];
    if ($fieldinfo['minlength']) {
        //验证规则
        $this->formValidateRules['info[' . $field . ']'] = array("required" => true);
        //验证不通过提示
        $this->formValidateMessages['info[' . $field . ']'] = array("required" => $errortips ? $errortips : $fieldinfo['name'] . "不能为空！");
    }
    $setting = unserialize($fieldinfo['setting']);
    $width = $setting['width'] ? $setting['width'] : 180;
    $html = '';


    //模块
    $module = MODULE_NAME;
    //生成上传附件验证
    $authkey = upload_key("1,{$setting['upload_allowext']},{$setting['isselectimage']},{$setting['images_width']},{$setting['images_height']},{$setting['watermark']}");
    //图片模式
    if ($setting['show_type']) {
        $preview_img = $value ? $value :'/statics/icon/upload-pic.png';
        return $str . "<div  style=\"text-align: center;\"><input type='hidden' name='info[$field]' class='filePicker_{$field} input-text' id='$field' value='$value'>
			<a href='javascript:void(0);' onclick=\"swfupload(this,'.filePicker_{$field}','');\" return false;\">
			<img src='$preview_img' class='filePicker_{$field}_img' id='{$field}_preview' width='135' height='113' style='cursor:hand' /></a>
                       <br/> " . $html . "
                   </div>";
    } else {
        //文本框模式
        return $str . "<input type='text' name='info[$field]' class='filePicker_{$field} input-text' id='$field' value='$value' style='width:{$width}px;' class='input' />  <input type='button' class=' btn btn-success radius' onclick=\"swfupload(this,'.filePicker_{$field}','');\" value='上传图片'>" . $html;
    }
}